<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <h1>{{name}}</h1>
    <my-h1></my-h1>
    <h1></h1>
    <my-h2></my-h2>
  </div>
</body>

</html>
<script src="../node_modules/vue/dist/vue.js"></script>
<script>
  /* 全局组件  局部组件 */
  // 局部组件 想在哪个组件中使用 就得在哪个组件中注册
  let myH2 = {
    data() {
      return {
        name: "局部组件"
      }
    },
    template: '<strong>{{name}}</strong>'
  }

  /* 
    Vue.component('组件名(不能是已经存在的html标签)',{配置项})
  */
  Vue.component('my-h1', {
    data() {
      return {
        name: "全局组件1",
      }
    },
    template: '<h1 @click="fn">{{name}} <my-h2></my-h2></h1>',
    methods: {
      fn() {
        console.log(this.name)
      }
    },
    components: {
      'my-h2': myH2
    }
  })



  let vm = new Vue({
    el: '#app',
    data: {
      name: "珠峰"
    },
    components: {
      'my-h2': myH2
    }
  });
</script>